<template>
  <div class="employees">
    <el-card class="btn">
      <el-button type="primary">导入</el-button>
      <el-button type="primary" @click="addStaff">+新增员工</el-button>
    </el-card>
    <el-card>
      <el-table v-show="bol" :data="list">
        <el-table-column label="序号">
          <template v-slot="{ $index }">
            {{ (page.page - 1) * page.size + $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="姓名" prop="username" />
        <el-table-column label="手机号" prop="mobile" width="200" />
        <el-table-column label="工号" prop="workNumber" />
        <el-table-column label="聘用形式" prop="formOfEmployment">
          <template v-slot="{ row }">
            <div>
              {{ +row.formOfEmployment | filterHireType }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="部门" prop="departmentName" />
        <el-table-column label="入职时间" prop="timeOfEntry" width="200">
          <template v-slot="{ row }">
            <div>
              {{ row.timeOfEntry | filterDate }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="是否在职" />
        <el-table-column label="状态" prop="" />
        <el-table-column label="操作" width="300" fixed="right">
          <template v-slot="{ row }">
            <el-button type="text">查看</el-button>
            <el-button type="text">转正</el-button>
            <el-button type="text">调岗</el-button>
            <el-button type="text">离职</el-button>
            <el-button type="text">角色</el-button>
            <el-button type="text" @click="del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="page">
        <!--
       -->
        <el-pagination
          :current-page="page.page"
          :page-sizes="[1, 5, 10, 20, 100, 200, 300, 400]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </el-card>

    <!-- dialog组件 -->
    <DialogCom ref="DialogCom" @handleCurrentChange="handleCurrentChange" />
  </div>
</template>
<script>
import { sysUserGet, sysUserDel } from '@/api/employees'
import DialogCom from './components/dialogCom.vue'
export default {
  name: 'Employees',
  components: { DialogCom },
  data() {
    return {
      bol: true,
      list: [],
      page: {
        page: 1,
        size: 10,
        total: 100
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await sysUserGet(this.page)
      this.list = res.data.rows
      this.bol = true
      this.page.total = res.data.total
    },
    handleCurrentChange(page) {
      this.page.page = page
      this.bol = false
      this.getData()
    },
    handleSizeChange(size) {
      this.page.size = size
      this.page.page = 1
      this.getData()
    },
    addStaff() {
      this.$refs.DialogCom.isShow = true
    },
    del(id) {
      this.$confirm('是否删除该员工', '温馨提示')
        .then(async() => {
          await sysUserDel(id)
          this.$message.success('删除成功')
          this.handleCurrentChange(1)
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="scss" scoped>
.employees {
  padding: 30px;
  .btn {
    margin-bottom: 15px;
    text-align: right;
  }
  .page {
    text-align: center;
    padding: 20px 0;
  }
}
</style>
